<template>
    <div class="report-woman">
        <el-form :inline="true" :model="formInline">
            <el-form-item label="城市">
                <el-input v-model="formInline.city" placeholder="城市" @keyup.enter.native="search"></el-input>
            </el-form-item>
            <el-form-item label="身份">
                <el-select v-model="formInline.identity" placeholder="关键字性质">
                <el-option label="全部" value=""></el-option>
                <el-option label="未认证" value="0"></el-option>
                <el-option label="已认证" value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="被举报人昵称">
                <el-input v-model="formInline.nickname" placeholder="被举报人昵称" @keyup.enter.native="search"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="search">搜索</el-button>
                <el-button type="primary" @click="reset">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table
            :header-cell-style="{color:'#555555'}"
            class="black"
            :data="tableData"
            stripe
            border
            style="width: 100%">
            <el-table-column
                prop="id"
                label="账号"
                align="center">
            </el-table-column>
            <el-table-column
                prop="createTime"
                label="最新举报时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="city"
                label="城市"
                align="center">
            </el-table-column>
            <el-table-column
                prop="reporterName"
                label="举报人昵称"
                align="center">
            </el-table-column>
            <el-table-column
                prop="nickname"
                label="被举报人昵称"
                align="center">
            </el-table-column>
            <el-table-column
                prop="is_vip"
                label="认证"
                align="center">
            </el-table-column>
            <el-table-column
                prop="content"
                label="历史消费"
                align="center">
            </el-table-column>
            <el-table-column label="操作" align="center" width="200">
                <template slot-scope="scope">
                    <el-button @click="onDetailClick(scope.row)" size="small">举报详情</el-button>
                    <el-button @click="onUserClick(scope.row)" size="small">用户资料</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="footer-page">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="page_size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total_page">
            </el-pagination>
        </div>
    </div>
</template>

<script>
export default {
    name: 'report-woman',
    data () {
        return {
            dialogVisible: false,
            params: {
                sex: 1,
                city: '',
                identity: '',
                nickname: '',
                page: 1,
                size: 10
            },
            page: 1,
            page_size: 10,
            total_page: 0,
            formInline: {
                city: '',
                identity: '',
                nickname: ''
            },
            tableData: [{
                id: '3056078', // 站点ID
                city: '北京', // 站点名称
                nickname: '榴莲包', // 网站类型
                createTime: '2018-09-02', // 创建时间
                is_vip: '是', // 是否vip
                content: '3454' // 历史消费
            } ]
        }
    },
    created () {
        this.tableData = []
    },
    mounted () {
        // 进来页面获取课程
        this.getList(this.params)
    },
    methods: {
        search () {
            this.page = 1
            this.params = {
                sex: 1,
                city: this.formInline.city,
                identity: this.formInline.identity,
                nickname: this.formInline.nickname,
                page: this.page,
                size: this.page_size
            }
            // 进来页面获取课程
            this.getList(this.params)
        },
        reset () {
            this.formInline = {
                station_id: '',
                station_name: '',
                station_url: '',
                station_state: '',
                station_code: ''
            }
        },
        onDetailClick (row) {
            this.$router.push({
                name: 'report.detail',
                params: {
                    data: row
                }
            })
        },
        onUserClick (row) {
            this.$router.push({
                name: 'detail.woman',
                params: {
                    id: row.userId
                }
            })
        },
        handleSizeChange (val) {
            this.page_size = val
            this.params.size = val
            // this.page = 1
            // this.params.page = 1
            this.getList(this.params)
        },
        handleCurrentChange (val) {
            this.page = val
            this.params.page = val
            this.getList(this.params)
        },
        getList (params) {
            let data = {
                'params': params
            }
            let _this = this
            this.$api.report.getReportData(data, res => {
                // 隐藏加载动画
                // this.$vux.loading.hide()
                if (res.code === 200) {
                    this.tableData = []
                    _this.getDetail(res.data.list)
                    this.total_page = res.data.totalCount
                    this.page = res.data.currPage
                    this.page_size = res.data.pageSize
                }
            })
        },
        getDetail (list) {
            let data = list || []
            let newArry = []
            for (let i = 0; i < data.length; i++) {
                this.tableData.push({
                    id: data[i].id || '',
                    city: data[i].city || '',
                    reporterName: data[i].reporterName || '',
                    reporterId: data[i].reporterId || '',
                    nickname: data[i].nickname || '',
                    userId: data[i].userId || '',
                    createTime: data[i].createTime || '',
                    is_vip: data[i].identity === 0 ? '未认证' : '已认证',
                    content: data[i].content || '',
                    images: data[i].images || []
                })
                if (i === data.length - 1) {
                    return (newArry)
                }
            }
        }
    }
}
</script>

<style lang="less" scoped>
    .report-woman {
        position: relative;
        width: 100%;
        height: 100%;
        .margin-bottom-12 {
            margin-bottom: 10px;
        }
        .el-row {
            margin-bottom: 20px;
            &:last-child {
                margin-bottom: 0;
            }
        }
        .el-col {
            border-radius: 4px;
        }
        .grid-content {
            position: relative;
            height: 40px;
        }
        .grid-padding {
            /* padding-left: 20px; */
            padding-right: 20px;
        }
        .grid-title {
            float: left;
            width: 72px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            color: #333;
            text-align: center;
        }
        .grid-input {
            float: left;
            width: 130px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            color: #333;
            text-align: center;
        }
        .row-bg {
            padding: 10px 0;
            background-color: #f9fafc;
        }
        .footer-page {
            width: 540px;
            margin: 0 auto;
            padding-top: 20px;
        }
    }
</style>
